package com.zmn.oms.dubbo.impl.normal.reply;

import com.alibaba.fastjson.JSON;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.oms.common.dio.normal.reply.ReplyAnswerDIO;
import com.zmn.oms.common.dro.normal.reply.ReplyAnswerDRO;
import com.zmn.oms.dubbo.interfaces.normal.reply.ReplyAnswerRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.entity.conf.reply.ReplyAnswer;
import com.zmn.oms.model.entity.conf.reply.ReplyAnswerQuery;
import com.zmn.oms.services.interfaces.conf.reply.ReplyAnswerService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 类描述：回访答案查询
 *
 * @author ligang
 * @since 2022/05/30 15:25
 */
@Slf4j
@DubboService(loadbalance = "roundrobin", timeout = 10000, retries = 0, version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class ReplyAnswerRemoteServiceImpl implements ReplyAnswerRemoteService {

    @Autowired
    private ReplyAnswerService replyAnswerService;

    @Override
    public ResponseDTO<List<ReplyAnswerDRO>> listReplyAnswerByQuery(ReplyAnswerDIO query) {
        log.info("回访答案查询入参：【{}】", JSON.toJSONString(query));
        try {
            ReplyAnswerQuery replyAnswerQuery = BeanMapper.map(query, ReplyAnswerQuery.class);
            List<ReplyAnswer> replyAnswerList = replyAnswerService.listByQuery(replyAnswerQuery);
            List<ReplyAnswerDRO> dros = BeanMapper.mapList(replyAnswerList, ReplyAnswerDRO.class);
            return ResponseDTO.success(dros);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("回访答案查询失败", e);
            return ResponseDTO.fail("回访答案查询失败，请稍后重试");
        }
    }
}
